import pymysql
'''
链接mysql数据库
'''

db = pymysql.connect(host='localhost',user='root',password='123456',db='cmswing',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)

try:
    cursor = db.cursor()

    sql = 'select * from cmswing_author  limit 10'

    cursor.execute(sql)

    data = cursor.fetchall()

    print(data)
except :
    db.rollback()

finally:
    db.close()

